package com.ouli.crowd.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ouli.crowd.entity.Role;
import com.ouli.crowd.mapper.RoleMapper;
import com.ouli.crowd.service.api.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.List;


@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageInfo<Role> getPageInfo(String keyword,Integer pageNum,Integer pageSize) {
        // 1.使用pageHelper开启分页功能
        PageHelper.startPage(pageNum,pageSize);
        // 2.获取到Role对象
        List<Role> list = roleMapper.selectRoleByKeyword(keyword);
        // 3.封装到pageInfo对象中

        return new PageInfo<>(list);
    }

    @Override
    public void deleteById(Integer roleId) {
        roleMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public void saveRole(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public Role selectById(int roleId) {
        return roleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public void updateById(Role role) {
        roleMapper.updateByPrimaryKey(role);
    }

    @Override
    public void deleteByIds(int[] arrays) {
        roleMapper.deleteByIds(arrays);
    }

    @Override
    public List<Role> selectByIds(int[] ids) {
        return roleMapper.selectByIds(ids);
    }
}
